package org.springblade.modules.restaurant.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.secure.BladeUser;
import org.springblade.core.secure.utils.SecureUtil;
import org.springblade.core.tool.api.R;
import org.springblade.modules.restaurant.service.IDashBoardService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author harry
 * @公众号 Harry技术
 */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/restaurant/dashboard")
@Tag(name = "DashBoard - 统计")
public class RestaurantDashBoardController {
	private IDashBoardService dashBoardService;


	@GetMapping("/dayIncomeExpenditureStatistics")
	@Operation(summary = "日收入支出统计", description = "日收入支出统计")
	public R dayIncomeExpenditureStatistics() {
		BladeUser user = SecureUtil.getUser();
		if (user == null) {
			return R.fail("请求异常，请重新登录");
		}
		// 获取当前登录用户ID
		Long userId = user.getUserId();
		String role = user.getRoleName();
		String tenantId = user.getTenantId();
		log.info("当前登录用户ID:{},role:{},tenantId:{}", userId, role, tenantId);
		Map<String, Object> map = dashBoardService.dayIncomeExpenditureStatistics(userId, tenantId, role);
		return R.data(map);
	}

	@GetMapping("/monthIncomeExpenditureStatistics")
	@Operation(summary = "月收入支出统计", description = "月收入支出统计")
	public R monthIncomeExpenditureStatistics() {
		BladeUser user = SecureUtil.getUser();
		if (user == null) {
			return R.fail("请求异常，请重新登录");
		}
		// 获取当前登录用户ID
		Long userId = user.getUserId();
		String role = user.getRoleName();
		String tenantId = user.getTenantId();
		log.info("当前登录用户ID:{},role:{},tenantId:{}", userId, role, tenantId);
		Map<String, Object> map = dashBoardService.monthIncomeExpenditureStatistics(userId, tenantId, role);
		return R.data(map);
	}

	@GetMapping("/areaMonthsScores")
	@Operation(summary = "区域月评分", description = "区域月评分")
	public R areaScores() {
		BladeUser user = SecureUtil.getUser();
		if (user == null) {
			return R.fail("请求异常，请重新登录");
		}
		// 获取当前登录用户ID
		Long userId = user.getUserId();
		String role = user.getRoleName();
		String tenantId = user.getTenantId();
		log.info("当前登录用户ID:{},role:{},tenantId:{}", userId, role, tenantId);

		Map<String, Object> map = dashBoardService.areaMonthsScores(userId, tenantId, role);
		return R.data(map);
	}

	@GetMapping("/dataCounts")
	@Operation(summary = "计数", description = "计数")
	public R dataCounts() {
		BladeUser user = SecureUtil.getUser();
		if (user == null) {
			return R.fail("请求异常，请重新登录");
		}
		// 获取当前登录用户ID
		Long userId = user.getUserId();
		String role = user.getRoleName();
		String tenantId = user.getTenantId();
		log.info("当前登录用户ID:{},role:{},tenantId:{}", userId, role, tenantId);

		List<Map<String, Object>> list = dashBoardService.dataCounts(userId, tenantId, role);
		return R.data(list);

	}

	@GetMapping("/taskStatistics")
	@Operation(summary = "任务统计", description = "任务统计")
	public R taskStatistics() {
		BladeUser user = SecureUtil.getUser();
		if (user == null) {
			return R.fail("请求异常，请重新登录");
		}
		// 获取当前登录用户ID
		Long userId = user.getUserId();
		String role = user.getRoleName();
		String tenantId = user.getTenantId();
		log.info("当前登录用户ID:{},role:{},tenantId:{}", userId, role, tenantId);

		Map<String, Object> map = dashBoardService.taskStatistics(userId, tenantId, role);
		return R.data(map);
	}

	@GetMapping("/attendanceStatistics")
	@Operation(summary = "点到统计", description = "点到统计")
	public R attendanceStatistics() {
		BladeUser user = SecureUtil.getUser();
		if (user == null) {
			return R.fail("请求异常，请重新登录");
		}
		// 获取当前登录用户ID
		Long userId = user.getUserId();
		String role = user.getRoleName();
		String tenantId = user.getTenantId();
		log.info("当前登录用户ID:{},role:{},tenantId:{}", userId, role, tenantId);

		Map<String, Object> map = dashBoardService.attendanceStatistics(userId, tenantId, role);
		return R.data(map);
	}

	// 日均人效 dailyHumanEfficiency
	@GetMapping("/dailyHumanEfficiency")
	@Operation(summary = "日均人效", description = "日均人效")
	public R dailyHumanEfficiency() {
		BladeUser user = SecureUtil.getUser();
		if (user == null) {
			return R.fail("请求异常，请重新登录");
		}
		// 获取当前登录用户ID
		Long userId = user.getUserId();
		String role = user.getRoleName();
		String tenantId = user.getTenantId();
		log.info("当前登录用户ID:{},role:{},tenantId:{}", userId, role, tenantId);

		Map<String, Object> map = dashBoardService.dailyHumanEfficiency(userId, tenantId, role);
		return R.data(map);
	}

	// 月均人效 monthlyHumanEfficiency
	@GetMapping("/monthlyHumanEfficiency")
	@Operation(summary = "月均人效", description = "月均人效")
	public R monthlyHumanEfficiency() {
		BladeUser user = SecureUtil.getUser();
		if (user == null) {
			return R.fail("请求异常，请重新登录");
		}
		// 获取当前登录用户ID
		Long userId = user.getUserId();
		String role = user.getRoleName();
		String tenantId = user.getTenantId();
		log.info("当前登录用户ID:{},role:{},tenantId:{}", userId, role, tenantId);

		Map<String, Object> map = dashBoardService.monthlyHumanEfficiency(userId, tenantId, role);
		return R.data(map);
	}
}
